package com.innoking.docsys.user.controller;

import com.innoking.docsys.user.dto.UpmsUser;
import com.innoking.docsys.user.module.UpmsUserVO;
import com.innoking.docsys.user.service.UserService;
import com.innoking.docsys.utils.*;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Administrator on 2019/8/15.
 */
@RestController
@RequestMapping("/api/user")
public class UserController {
    Logger logger= LoggerFactory.getLogger(UserController.class);

    @Autowired
    UserService userService;


    /**
     * 用户登录验证
     * @param data
     * @return
     */
    @PostMapping("/loginIn")
    public ResultObjVO home(@RequestBody String data) {

        logger.info("Hello loginIn");
        OtherPojo ob = JsonToOtherUtil.rtOtherPojo(data, new UpmsUserVO() );
        UpmsUserVO user=(UpmsUserVO)ob.getObj();
        ResultObjVO res=userService.checkUserLoginLegal(user);
        return res;

    }
    @PostMapping("/getUserbyId")
    public ResultObjVO getUserbyId(@RequestBody String data) {
        logger.info("Hello home");
        OtherPojo ob = JsonToOtherUtil.rtOtherPojo(data, new UpmsUser() );
        UpmsUser user=(UpmsUser)ob.getObj();
       if(user.getUserId()== null ){
           return  ResultUtil.error("用户id参数为空");
       }
        UpmsUser userObj=userService.getUserbyId(  user.getUserId().intValue() );
        if(userObj==null){
            return  ResultUtil.emptyData();
        }
        UpmsUserVO vo= new UpmsUserVO();
        BeanUtils.copyProperties(userObj,vo);
        return ResultUtil.success(vo );
    }
}